#
# Package.
#

package iSOCK::Controller::Admin::Components;

#
# Parent.
#

use Moose;
use namespace::autoclean;

BEGIN { extends 'iSOCK::Controller::Root' }

#
# Uses.
#

use Try::Tiny;

#
# Documentation.
#

=head1 NAME

iSOCK::Controller::Admin::Components - AdminComponents  Controller for iSOCK

=head1 DESCRIPTION

[enter your description here]

=head1 METHODS

=cut

#
# Subs.
#

sub index :Path :Args(0) {
  my ( $self, $c ) = @_;

  $self->check_user_authorization ( $c, 'can_bofh' );
  
  my $parameters = $c->request->parameters;
  
  if ( $c->request->method eq 'POST' && $parameters->{form_components_create} ) {
    try {
      $c->model ( 'App' )->create_component ({ id => $parameters->{component_id} });
      
      $c->stash->{action_succeeded} = "Created $parameters->{component_id} component.";
    }
    catch {
      ( my $why = $_ ) =~ s/ at \/.+\.$//;
      
      $c->stash->{action_failed} = $why;
    };
  }
  
  $c->stash (
    components        => $c->model ( 'App'                )->components_loh,
    component_type_rs => $c->model ( 'App::ComponentType' ),
  );

  $c->forward ( qw( iSOCK::Controller::Root render_view ) );
}

#
# Documentation.
#

=head1 AUTHOR

Xavier Caron

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

#
# End of iSOCK::Controller::Products.
#

1;
